from django.shortcuts import render
from django.http import JsonResponse

# Create your views here.

permissionRouter = {
    "path": "/permission",
    "name": "permission",
    "redirect": "/permission/page/index",
    "meta": {
        "title": "menus.permission",
        "icon": "Lollipop",
        "i18n": True,
        "showLink": True,
        "rank": 3
    },
    "children": [
        {
            "path": "/permission/page/index",
            "name": "permissionPage",
            "meta": {
                "title": "menus.permissionPage",
                "i18n": True,
                "showLink": True
            }
        },
        {
            "path": "/permission/button/index",
            "name": "permissionButton",
            "meta": {
                "title": "menus.permissionButton",
                "i18n": True,
                "showLink": True,
                "authority": []
            }
        }
    ]
}


def set_dif_authority(authority, routes):
    routes["children"][1]["meta"]["authority"] = [authority]
    return routes


def async_routers(request):
    if request.GET["name"] == "admin":
        return JsonResponse({
            "code": 0,
            "info": [set_dif_authority("v-admin", permissionRouter)]
        })
    else:
        return JsonResponse({
            "code": 0,
            "info": [set_dif_authority("v-test", permissionRouter)]
            }
        )
